#coding=utf-8
#Boa:FramePanel:PanelSaleUnaudit

import wx

from MyListCtrl import MyOrderListCtrl
from product import CDataSaleOrder

[wxID_PANELSALEUNAUDIT, wxID_PANELSALEUNAUDITBTNAUDIT, 
 wxID_PANELSALEUNAUDITBTNREFRESH, 
] = [wx.NewId() for _init_ctrls in range(3)]

class PanelSaleUnaudit(wx.Panel):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Panel.__init__(self, id=wxID_PANELSALEUNAUDIT,
              name=u'PanelSaleUnaudit', parent=prnt, pos=wx.Point(187, 63),
              size=wx.Size(1051, 703), style=wx.TAB_TRAVERSAL)
        self.SetClientSize(wx.Size(1043, 669))
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Arial'))
        self.SetBackgroundColour(wx.Colour(183, 209, 173))

        self.btnRefresh = wx.Button(id=wxID_PANELSALEUNAUDITBTNREFRESH,
              label=u'\u5237\u65b0', name=u'btnRefresh', parent=self,
              pos=wx.Point(16, 8), size=wx.Size(86, 26), style=0)
        self.btnRefresh.Bind(wx.EVT_BUTTON, self.OnBtnRefreshButton,
              id=wxID_PANELSALEUNAUDITBTNREFRESH)

        self.btnAudit = wx.Button(id=wxID_PANELSALEUNAUDITBTNAUDIT,
              label=u'\u5ba1\u6838', name=u'btnAudit', parent=self,
              pos=wx.Point(128, 8), size=wx.Size(86, 26), style=0)
        self.btnAudit.Bind(wx.EVT_BUTTON, self.OnBtnAuditButton,
              id=wxID_PANELSALEUNAUDITBTNAUDIT)

    def __init__(self, parent):
        self._init_ctrls(parent)

        self.lcBill = MyOrderListCtrl(self)
        self.lcBill.SetSize(wx.Size(1000, 550))
        self.lcBill.Move(wx.Point(10,38))
        self.lcBill.refresh({'audit':False}) # 错写作Refresh，导致调试N久...避免类似函数名

    def OnBtnRefreshButton(self, event):
        self.lcBill.refresh({'audit':False})

    def OnBtnAuditButton(self, event):
        item = self.lcBill.GetNextItem(-1, state = wx.LIST_STATE_SELECTED)
        if (item == -1):
            return      
                
        dlg = wx.MessageDialog(self, u'单据审核之后不能编辑，如需编辑，请先反审核，是否审核通过?',u'提示',
                                wx.YES_NO|wx.ICON_QUESTION)
        if(dlg.ShowModal() == wx.ID_NO):
            return
        
        CDataSaleOrder.update_item(self.lcBill.getBillId(item), {CDataSaleOrder.COL_AUDIT:1})
        self.lcBill.refresh({'audit':False})
